﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
namespace HRP
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {            
            if (!Session.IsNewSession)
                Response.Redirect("~/private/main.aspx", false);

            if (!IsPostBack)
            {
                Label1.Text = "";
            }
        }

        protected void loginLinkBT_Click(object sender, EventArgs e)
        {
            string username = usernameTB.Text;
            string password = passwordTB.Text;
            try
            {
                var dadosLogin = Cliente_BLL.Instance.loginClient(username, password);
                Session.Clear();
                //check empresa tem produto valido

                var empresaValida = Cliente_BLL.Instance.checkValid(Convert.ToInt32(dadosLogin.idClient));

                if (empresaValida == null)
                {
                    Label1.Text = "Periodo Contratualizado Expirou.";
                    return;
                }

                if (dadosLogin!= null)
                {
                    Session.Add("SessionID", Session.SessionID);
                    Session.Add("valid", 1);
                    Session.Add("userid", dadosLogin.id);
                    Session.Add("idclient", dadosLogin.idClient);
                    Session.Add("user", dadosLogin.username);
                    string name = dadosLogin.Name;
                    int pos = name.ToString().IndexOf(" ");
                    name = name.Substring(0, pos);
                    Session.Add("name", name);
                    Response.Redirect("~/private/main.aspx", false);
                }
                else
                {
                    Label1.Text = "User or Password Incorrect";
                }





            }
            catch (Exception)
            {
                Label1.Text = "User or Password Incorrect";
               // throw;
            }
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/public/RecuperarSenha.aspx", false);
        }
    }
}